<?
	$level2;
	$level3;
	//HOME TOP LINK TO BACK
	$HomeLink = "<div><a href=\"".$root."/trang-chu/\">Trang chủ</a></div>";
	if(isset($_GET['cid'])){
		$cid = intval($_GET['cid']);
		$level2 = $cid;
		
		$c_id_cha;
			do{
				$rs = $db->query("SELECT c_id_cha FROM ".$prefix."loaisanpham where c_hienthi = 1 AND c_id = '".$level2."'");
				$row = $db->fetch_array($rs);
				$c_id_cha = $row[c_id_cha];
				if($c_id_cha != 0){
					$level3 = $level2;
					$level2 = $c_id_cha;
				}
			}while($c_id_cha != 0);
		
		$rs = $db->query("SELECT * FROM ".$prefix."loaisanpham WHERE c_id = '".$cid."' AND c_hienthi = 1");
		if($db->num_rows($rs) != 0){
			$row = $db->fetch_array($rs);
			
			if($row[c_id_cha] == 0){
				$cat_name = stripslashes($row[c_ten]);
				$cat_id = $row[c_id];
				$HomeLink .= "<div><a>".$cat_name."</a></div>";
			}else{
				$c_name = stripslashes($row[c_ten]);
				$cat_id = $row[c_id_cha];
				$rs2 = $db->query("SELECT * FROM ".$prefix."loaisanpham WHERE c_id = '".$cat_id."' AND c_hienthi = 1");
				$row2 = $db->fetch_array($rs2);
				$cat_name = stripslashes($row2[c_ten]);
				$HomeLink .= "<div><a href=\"".$root."/danh-muc-san-pham/".$cat_id."/".$myString->vietdecode($cat_name)."\">".$cat_name."</a></div><div><a>".$c_name."</a></div>";
			}
		}else{echo $reHome;}
	}else{echo $reHome;}
	
?>
    <!-- Main Page-Content { -->  
    <? if($row[c_id_cha] == 0){ ?>   	
    
<div class="linkPath">
    <div class="linkPath-text">    
        <?=$HomeLink?>

        <?
			file_exist('includes/inc_thong_tin_rieng.php');
			include('includes/inc_thong_tin_rieng.php');
		?>
    </div>
</div>
    	
    	
<!-- Showcase List { -->
<div class="panel-left">
<?
	$rs = $db->query("SELECT * FROM ".$prefix."loaisanpham where c_hienthi = 1 AND c_id_cha = '".$row[c_id]."'");	
	if($db->num_rows($rs) != 0) {
	while($row = $db->fetch_array($rs)){
		$c_ten = stripcslashes($row[c_ten]);
		$c_id = $row[c_id];	
?>
<!-- showcase { -->

<div class="box-cate">	
	<div class="header">
		<div class="title" >
			<a href="<?=$root?>/danh-muc-san-pham/<?=$c_id?>/<?=$myString->vietdecode($c_ten)?>" title="<?=$c_ten?>"><?=$c_ten?></a>
		</div>
	</div>
	<div class="content">
		<div class="all">
			<div class="boxcate-inside">
				<table class="tblCate" cellspacing="13">
					<tr>
						<?
						//Lay danh sach cac id subcat
						//$listId = layDanhSachSubCatId($c_id);
						$rs2 = $db->query("SELECT * FROM ".$prefix."loaisanpham WHERE c_hienthi = 1 AND c_id_cha = '".$c_id."'");

						if($db->num_rows($rs2) != 0){
							$i = 0;
						?>	
							<td class="cateItem" width="25%" valign="top">
						<?
							while($row2 = $db->fetch_array($rs2)){							
								if($i < 5) {						
								$c_id2 = $row2[c_id];
								$c_ten2 = stripcslashes($row2[c_ten]);
						?>
								<a href="<?=$root?>/danh-muc-san-pham/<?=$c_id2?>/<?=$myString->vietdecode($c_ten2)?>" title="<?=$c_ten2?>"><?=$c_ten2?></a>
							
								<? $i++; } else {
									echo "</td>";
									$i = 0;
								?>
									<td class="cateItem" width="25%" valign="top">
								<? } ?>
						<? } ?>						
					<? } ?>
					</tr>
				</table>
			</div>
		</div>
	</div>
</div>
<div style="clear:both"></div>
	
<!-- } showcase -->		
<? } ?>
<? } ?>        

<div class="clear-showcase"></div>
     
				<!-- } Showcase List -->
</div>    
    
    	
    <? } else{ ?>         
  
  <!-- BEGIN MAIN -->
  <div class="box-mn-head">
  	<div class="content" style="margin-bottom: 0;">
  		<div id="boxcate-inside" align="left">
  			<table class="tblCate" cellspacing="0">
  				<tr>  					 					
  					<?
						//Lay danh sach cac id subcat
						//$listId = layDanhSachSubCatId($c_id);
						$rs2 = $db->query("SELECT * FROM ".$prefix."loaisanpham WHERE c_hienthi = 1 AND c_id_cha = '".$level3."'");

						if($db->num_rows($rs2) != 0){
							$i = 0;
						?>	
							<td class="cateItem" width="25%" valign="top">
						<?
							while($row2 = $db->fetch_array($rs2)){							
								if($i < 5) {						
								$c_id = $row2[c_id];
								$c_ten = stripcslashes($row2[c_ten]);
						?>
								<a href="<?=$root?>/danh-muc-san-pham/<?=$c_id?>/<?=$myString->vietdecode($c_ten)?>" title="<?=$c_ten?>"><?=$c_ten?></a>
							
								<? $i++; } else {
									echo "</td>";
									$i = 0;
								?>
									<td class="cateItem" width="25%" valign="top">
								<? } ?>
						<? } ?>						
					<? } ?>
  				</tr>
  			</table>
  		</div>
  	</div>
  </div>
  

<div class="linkPath">
    <div class="linkPath-text">    
        <?=$HomeLink?>

        <?
			file_exist('includes/inc_thong_tin_rieng.php');
			include('includes/inc_thong_tin_rieng.php');
		?>
    </div>
</div>
<div id="page-content-mpane-all">
            
			<!-- PRODUCT TOP -->
			
			<? 
				file_exist('includes/chungloai/inc_top_product.php');
				include('includes/chungloai/inc_top_product.php');
			?>
			
			<!-- END PRODUCT TOP -->

            
            <!-- CONTENT -->
			
			<?
				file_exist('includes/chungloai/inc_home.php');
				include('includes/chungloai/inc_home.php');
			?>
			
			<!-- CONTENT -->


                              
        </div>
        <? } ?>  
    <div style="clear:both;"></div>      
    <!-- } Main Page-Content --> 
</div>
